package com.neusmart.fs.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.neusmart.fs.F;
import com.neusmart.fs.R;
import com.neusmart.fs.constants.API;
import com.neusmart.fs.model.MParam;

public class ChangeUserMassageNextActivity extends DataLoadActivity implements View.OnClickListener{
     private EditText characterization,required;
     private String height;
     private Bundle bundle;

    @Override
        protected int getLayoutResID() {
        return R.layout.activity_change_user_massage_next;
    }

    @Override
    protected void init() {
        loadExtraData();
        initView();
        setContent();
        setListener();
    }

    private void intoBundle() {
        bundle.putString("characterization",characterization.getText().toString());
        bundle.putString("required",required.getText().toString());
    }

    private void loadExtraData() {
        bundle = getIntent().getExtras();
        if (bundle == null)
            return;

    }

    private void setContent() {
        characterization.setText(F.mUserInfo.getCharacterization());
        required.setText(F.mUserInfo.getPersonal_required());
    }

    private void initView() {
        characterization= (EditText) findViewById(R.id.characterization_editText);
        required= (EditText) findViewById(R.id.request_editText);
    }
    private void setListener() {
        int[] resIds = {R.id.my_data_btn_back,R.id.btn_next};
        for (int id : resIds)
            findViewById(id).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.my_data_btn_back:
                onBackPressed();
                break;
            case R.id.btn_next:
                if (characterization.getText().toString().length()==0){
                   showToast("请输入个人描述");
                    return;
                }else if (characterization.getText().toString().toCharArray().length<6){
                    showToast("个人描述不少于6个字");
                    return;
                }else if (required.getText().toString().length()==0){
                    showToast("请输入征友要求");
                    return;
                }else if (required.getText().toString().toCharArray().length<6){
                    showToast("征友要求不少于6个字");
                    return;
                }else {
                    if (F.mUserInfo.getUser_status()==0){//新用户
                        loadData(API.UPDATE_PROFILE, true);
                    }else {
                        intoBundle();
                        switchActivity(UpDataUserPicActivity.class,bundle);
                    }
                }
                break;
            default:
                break;
        }
    }


    @Override
    protected void initParams(MParam param) {
        switch (param.getApi()) {
            case UPDATE_PROFILE:
                param.addParam("personal_required", required.getText().toString());
                param.addParam("characterization", characterization.getText().toString());
                param.addParam("needUpdateStatus",false);//1
                break;
            default:
                break;
        }
    }
    @Override
    protected void disposeResult(API api, String response) {
        if (response == null)
            return;
        switch (api) {
            case UPDATE_PROFILE:
                intoBundle();
                //switchActivity(ChangeUserMassageLastActivity.class,bundle);
                switchActivity(UpDataUserPicActivity.class,bundle);
                break;
            default:
                break;
        }
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.getInstance().addActivity(this);
        initSwipeBackFinish(true);
    }
    @Override
    public void onDestroy() {
        super.onDestroy();

    }

}
